from time import sleep
import uiautomation
import pyautogui
class shoushushenqing():
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        his.SetFocus()

        xingmingshurukuang = his.EditControl(ClassName='TextBox',foundIndex=5)
        chaxun = his.ButtonControl(ClassName='Button',Name='查询')
        shoushuanpai = his.ButtonControl(ClassName='Button',Name='手术安排')
        bianji = his.ButtonControl(ClassName='Button',Name='编辑')
        #手术数据1
        shuju1 = his.DataItemControl(ClassName='DataGridRow',Name='Yuanbo.ChssClient.InPatient.Model.SSManage.SSSQDMODEL',foundIndex=1)



#手术安排窗口
        shoushuanpaichuangkou = his.WindowControl(ClassName='Window',Name='手术安排')
        shoushuanpaiqueding = shoushuanpaichuangkou.GroupControl(Name='操作区').ButtonControl(ClassName='Button',Name='手术安排')

#手术记录窗口
        shoushujiluchuangkou = his.WindowControl(ClassName='Window',Name='手术记录')
        #手术记录操作区
        ssjl_bc = shoushujiluchuangkou.GroupControl(Name='操作区').ButtonControl(AutomationId='btn_save',ClassName='Button',Name='保存')
        ssjl_shbg = shoushujiluchuangkou.GroupControl(Name='操作区').ButtonControl(AutomationId='AuditReport',ClassName='Button',Name='审核报告')
        ssjl_tjfy = shoushujiluchuangkou.GroupControl(Name='操作区').ButtonControl(AutomationId='SubmissionFee',ClassName='Button',Name='提交费用')
        ssjl_gb = shoushujiluchuangkou.GroupControl(Name='操作区').ButtonControl(ClassName='Button',Name='关闭')
        #关闭窗口
        def close_window(self):
                self.shoushujiluchuangkou.GetWindowPattern().Close()
        # 点击手术记录保存
        def click_ssjl_bc(self):
                self.ssjl_bc.Click()
        # 点击手术记录审核报告
        def click_ssjl_shbg(self):
                self.ssjl_shbg.Click()
        # 点击手术记录提交费用
        def click_ssjl_tjfy(self):
                self.ssjl_tjfy.Click()
        # 点击手术记录关闭
        def click_ssjl_gb(self):
                self.ssjl_gb.Click()

        # 手术记录显示录入区
        #手术记录
        shoushujilu = his.TabControl(AutomationId='tabAll', ClassName='TabControl').TabItemControl(AutomationId='TABSSJL', ClassName='TabItem', Name='手术记录')
        zhudaoyisheng = shoushujilu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=2)
        mazuiyisheng = shoushujilu.EditControl(AutomationId='PART_TextBox',ClassName='TextBox',foundIndex=3)
        mazuifangshi = shoushujilu.ComboBoxControl(ClassName='ComboBox',foundIndex=2)
        qiekoudengji = shoushujilu.ComboBoxControl(ClassName='ComboBox',foundIndex=3)
        yuhedengji = shoushujilu.ComboBoxControl(ClassName='ComboBox',foundIndex=4)
        wujunchengdu = shoushujilu.ComboBoxControl(ClassName='ComboBox',foundIndex=5)
        shuzhongyingliu =  shoushujilu.ComboBoxControl(ClassName='ComboBox',foundIndex=7)
        #选择主刀医生
        def choose_zdys(self,zdys):
                self.zhudaoyisheng.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.zhudaoyisheng.SendKeys(zdys)
                sleep(1)
                pyautogui.press('enter')
        #选择麻醉医生
        def choose_mzys(self,mzys):
                self.mazuiyisheng.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.mazuiyisheng.SendKeys(mzys)
                sleep(1)
                pyautogui.press('enter')
        #选择麻醉方式
        def choose_mzfs(self):
                self.mazuifangshi.Click()
                self.mazuifangshi.GetLastChildControl().Click()
        #选择切口等级
        def choose_qkdj(self):
                self.qiekoudengji.Click()
                self.qiekoudengji.GetLastChildControl().Click()
        #选择愈合等级
        def choose_yhdj(self):
                self.yuhedengji.Click()
                self.yuhedengji.GetLastChildControl().Click()
        # 选择无菌程度
        def choose_wjcd(self):
                self.wujunchengdu.Click()
                self.wujunchengdu.GetLastChildControl().Click()
        #填写手术记录保存
        def fill_ssjl(self,zdys,mzys):
                self.choose_zdys(zdys)  # 选择主刀医生
                self.choose_mzys(mzys)  # 选择麻醉医生
                self.choose_mzfs()
                self.choose_qkdj()
                self.choose_yhdj()
                self.choose_wjcd()
                self.click_ssjl_bc()





        #手术收费选项卡
        shoushushoufei = his.TabControl(AutomationId='tabAll', ClassName='TabControl').TabItemControl(AutomationId='TABSSSF', ClassName='TabItem', Name='手术收费')
        shujuwangge = his.DataGridControl(AutomationId='dgMedInput', ClassName='YDataGrid')
        shuju001 = shujuwangge.DataItemControl( ClassName='DataGridRow',SubName='ZhuYuanFeiYongBuLuModel',foundIndex=1).CustomControl(ClassName='DataGridCell',SubName='列显示索引: 0',foundIndex=1)
        xiangmumingcheng1 = shuju001.EditControl(AutomationId='PART_TextBox')
        shuju002 = shujuwangge.DataItemControl(ClassName='DataGridRow', SubName='ZhuYuanFeiYongBuLuModel', foundIndex=2).CustomControl(ClassName='DataGridCell',SubName='列显示索引: 0',foundIndex=1)
        xiangmumingcheng2 = shuju002.EditControl(AutomationId='PART_TextBox')
        shuju003 = shujuwangge.DataItemControl(ClassName='DataGridRow', SubName='ZhuYuanFeiYongBuLuModel', foundIndex=3).CustomControl(ClassName='DataGridCell',SubName='列显示索引: 0',foundIndex=1)
        xiangmumingcheng3 = shuju003.EditControl(AutomationId='PART_TextBox')
        shuju004 = shujuwangge.DataItemControl(ClassName='DataGridRow', SubName='ZhuYuanFeiYongBuLuModel', foundIndex=4).CustomControl(ClassName='DataGridCell',SubName='列显示索引: 0',foundIndex=1)
        xiangmumingcheng4 = shuju004.EditControl(AutomationId='PART_TextBox')
        shuju005 = shujuwangge.DataItemControl(ClassName='DataGridRow', SubName='ZhuYuanFeiYongBuLuModel', foundIndex=5).CustomControl(ClassName='DataGridCell',SubName='列显示索引: 0',foundIndex=1)
        xiangmumingcheng5 = shuju005.EditControl(AutomationId='PART_TextBox')



        #输入数据1
        def input_sj1(self,sj):
                self.shuju001.DoubleClick()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.xiangmumingcheng1.SendKeys(sj)
                sleep(1)
                pyautogui.press('enter')
        #输入数据2
        def input_sj2(self,sj):
                self.shuju002.DoubleClick()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.xiangmumingcheng2.SendKeys(sj)
                sleep(1)
                pyautogui.press('enter')
        #输入数据3
        def input_sj3(self,sj):
                self.shuju003.DoubleClick()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.xiangmumingcheng3.SendKeys(sj)
                pyautogui.press('enter')
        #输入数据4
        def input_sj4(self,sj):
                self.shuju004.DoubleClick()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.xiangmumingcheng4.SendKeys(sj)
                pyautogui.press('enter')
        #输入数据5
        def input_sj5(self,sj):
                self.shuju005.DoubleClick()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.xiangmumingcheng5.SendKeys(sj)
                pyautogui.press('enter')
        # 手术收费右键菜单
        caidan = his.MenuControl(ClassName='ContextMenu')
        zengjia = caidan.MenuItemControl(ClassName='MenuItem', Name='增加')
        fuzhi = caidan.MenuItemControl(ClassName='MenuItem', Name='复制')
        shanchu = caidan.MenuItemControl(ClassName='MenuItem', Name='删除')
        chongjian = caidan.MenuItemControl(ClassName='MenuItem', Name='冲减')
        #点击增加手术收费项目
        def add_sssfxm(self, num: int):
                for i in range(num):
                        uiautomation.RightClick(779,677)
                        self.zengjia.Click()

        shoushuyizhu = his.TabControl(AutomationId='tabAll', ClassName='TabControl').TabItemControl(AutomationId='TABSSYZ', ClassName='TabItem', Name='手术医嘱')
        #点击手术记录
        def click_ssjl(self):
                self.shoushujilu.Click()
        #点击手术收费
        def click_sssf(self):
                self.shoushushoufei.Click()
        #点击手术医嘱
        def click_ssyz(self):
                self.shoushuyizhu.Click()

        #输入患者姓名
        def input_name(self,name):
                self.xingmingshurukuang.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.xingmingshurukuang.SendKeys(name)

        #点击查询
        def click_cx_btn(self):
                self.chaxun.Click()
        #点击手术安排
        def click_ssap_btn(self):
                self.shoushuanpai.Click()
        #点击编辑
        def click_bj_btn(self):
                self.bianji.Click()
        #点击数据1
        def click_sj1(self):
                self.shuju1.Refind()
                self.shuju1.Click()
        #安排手术并关闭窗口
        def choose_ssap(self):
                self.click_ssap_btn()
                self.shoushuanpaiqueding.Click()
                self.shoushuanpaichuangkou.GetWindowPattern().Close()